//
//  ViewController.swift
//  swift-第一个应用程序
//
//  Created by hanbo on 2018/10/24.
//  Copyright © 2018年 hanbo. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    // MARK: - 视图生命周期
    // MARK: 视图加载完成
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        // 1.创建一个视图
        let v = UIView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
        v.center = view.center;
        // 设置背景颜色
        v.backgroundColor = #colorLiteral(red: 0.9411764741, green: 0.4980392158, blue: 0.3529411852, alpha: 1)     // TODO:应该设置背景颜色
        // 添加到当前视图 访问当前的属性,可以不使用`self`,建议:都不用,原因:闭包(类似于 OC bocl,需要使用self.)
        view.addSubview(v)
        
        // 2.创建一个按钮
        let btn = UIButton(type: .contactAdd)
        
        v.addSubview(btn)
        
        btn.addTarget(self, action: #selector(clickMe), for: .touchUpInside)

        
        // 监听方法 swift: #selector OC:@selector 带参数,不需要使用冒号
        
        let img = UIImageView(image: #imageLiteral(resourceName: "启动图标1024"))  // FIXME:应该设置图片
        
//        img.center = view.center
        
        img.frame = CGRect(x: 200, y: 200, width: 100, height: 100)
        
        
        view.addSubview(img)
        
        
    }
    
    
    @objc func clickMe(btn:UIButton) -> () {
        print(#function)
        print("哈哈哈")
        print(btn)
    }

    
    // MARK: 接收到内存警告
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

